package ca.ubc.icapture.genapha.actions;

import ca.ubc.icapture.genapha.forms.AnalysisFilesForm;
import ca.ubc.icapture.genapha.forms.FbatContinuousForm;
import icapture.SQLMgr;
import icapture.genapha.GenotypeToolsManager;

import java.util.ArrayList;

/**
 * Created by IntelliJ IDEA.
 * User: btripp
 * Date: Sep 13, 2006
 * Time: 9:38:59 AM
 * To change this template use File | Settings | File Templates.
 */
public class FbatContinuousAction extends AnalysisFilesAction
{

    @Override
    protected void processRequest(AnalysisFilesForm form)
    {
        final FbatContinuousForm contForm = (FbatContinuousForm) form;
        final Integer phenotypeid = Integer.valueOf(contForm.getSelectedPhenotype());
        GenotypeToolsManager gtm = new GenotypeToolsManager();

        // Add name to the result
        if (contForm.getSelectedCohort().length > 1)
        {
            result.setName("Combined Continous Phenotype Linkage File");
        }
        else
        {
            result.setName("Unphased Format Continous Phenotype Linkage File");
        }
        SQLMgr.updateResult(result);

        // If there is more than 1 cohort or if it is explicitly requested,
        // unphased format should be used.
        if (contForm.getSelectedCohort().length > 1 || contForm.isUnPhasedFormat())
        {
            gtm.writeCombinedfbatBinaryVariableInputFileFromDB(phenotypeid, contForm.getSelectedCohort(),
                    contForm.isRemoveMzTwins(), contForm.isRemoveDuplicateSubjects(),
                    contForm.getSelectedGenes(), contForm.getEmail(), result, gtm.UNPHASED_FORMAT, false);
        }
        else
        {
            gtm.writefbatContinousVariableInputFileFromDB(contForm.getEmail(), Integer.valueOf(contForm.getSelectedCohort()[0]),
                    phenotypeid, contForm.isRemoveMzTwins(), contForm.isRemoveDuplicateSubjects(),
                    result, new ArrayList<Integer>());

        }
    }
}
